/********************************************************************
 * Copyright(c) 2023-2023 Grayson Zheng.
 * File: bit.h
 * Description: PWM output header file based on 89C52 timer 2.
 * Version: 1.0
 * Date: 2023-07-25
 * Author: zhengxinyu13@qq.com
 * ---------- Revision History ----------
 * <version>
 * <date>
 * <author>
 * <desc>
 * Modified to be suitable to the new coding rules in all functions.
 ********************************************************************/

#include "regx52.h"
#include "STC89C5xRC-rdp.h"
#include "datatype.h"
#include "bit.h"

#ifndef __PWM_TIMER2_H__
#define __PWM_TIMER2_H__

#define MACHINE_CYCLE (fp_64)(12000000.00/11059200.00)

/* The default cycle is 20,000us */
#define PWM_CYCLE (uint_16)(20000.00 / MACHINE_CYCLE)

/* The default duty cycle is 5000us */
#define PWM_DUTY_RATIO (uint_16)(5000 / MACHINE_CYCLE)

#define PWM_INACTIVE_TIME (uint_16)(PWM_CYCLE - PWM_DUTY_RATIO)

#define UINT_16_MAX 65535

sbit PWM_OUTPUT = P3^7;

void time2_init(void);
void set_duty_ratio_xus(uint_16 xus);
void set_duty_ratio_percentage(fp_32 percentage);

#endif